
package com.testcolision;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;

public class OnscreenControlRenderer {
	SpriteBatch batch;
	TextureRegion dpad;
	TextureRegion left;
	TextureRegion right;
	TextureRegion jump;
	TextureRegion cubeControl;
	TextureRegion cubeFollow;
	
	float screenHeight, screenWidth;
	

	public OnscreenControlRenderer ( ) {
	
		screenHeight = Gdx.graphics.getHeight();
		screenWidth =  Gdx.graphics.getWidth();
		loadAssets();
	}

	private void loadAssets () {
		Texture texture = new Texture(Gdx.files.internal("data/controls.png"));
		TextureRegion[] buttons = TextureRegion.split(texture, 64, 64)[0];
		left = buttons[0];
		right = buttons[1];
		jump = buttons[2];
		cubeControl = buttons[3];
		cubeFollow = TextureRegion.split(texture, 64, 64)[1][2];
		dpad = new TextureRegion(texture, 0, 64, 128, 128);
		batch = new SpriteBatch();
		batch.getProjectionMatrix().setToOrtho2D(0, 0, screenWidth, screenHeight);
	}

	public void render () {
			batch.begin();
			batch.draw(left, 0, 0);
			batch.draw(right, 70, 0);
			 
			batch.draw(jump, screenWidth - 64, 0);
		 
			//batch.draw(dpad, 0, 0);
			batch.draw(cubeFollow, screenWidth - 64, 64);
			batch.draw(cubeControl, screenWidth - 64, screenHeight - 64);
			batch.end();
		
	}

	public void dispose () {
		dpad.getTexture().dispose();
		batch.dispose();
	}
}
